var api = require('../../utils/api.js');
var app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
      tops:32,
      icons:[],
      status:['未完成','已完成','全部'],
      users:[],
      users_tit:'',
      users_id:'',
      merch:[], 
      merch_tit:'',
      merch_id:'',
      orders:[],
      order_tit:'',
      order_id:'',
      icons:[],
      icons_id:'',
      icons_tit:'',
      lists:[],
      status_id:'0',
      status_t:'未完成'
    },

    seeinfo(ret){
        console.log(ret)

            var id=ret.currentTarget.dataset.id;

            wx.navigateTo({
              url: '/pages/note/info?id='+id
            })

    },

    getallnote(){
        var that=this;
        var status_id=this.data.status_id;
        var users_id=this.data.users_id;
        var merch_id=this.data.merch_id;
        var order_id=this.data.order_id;
        var icons_id=this.data.icons_id;

        that.setData({
            lists:[]
        })
       
        api.post({
            url: 'icons/getallnote',
            data: {icons_id:icons_id,order_id:order_id,merch_id:merch_id,users_id:users_id,status_id:status_id},
            success: data => {
                that.setData({
                    lists:data.data
                })
            }
        })


    },

    //状态
    bindPickerChangestatus(ret){
        var index=ret.detail.value;
        console.log(ret);
        var status_t='全部';
        if (index==1){
            status_t='已完成';
        }else  if (index==0){
            status_t='未完成';
        }

        this.setData({
            status_t:status_t,
            status_id:index,
            lists:[]
        })

        this.getallnote();
    },

    //标签
    bindPickerChangeicon(ret){
        console.log(ret);
        var index=ret.detail.value;
        var merch=this.data.icons;

        var merch_tit=merch[index].name
        var merch_id=merch[index].id

        this.setData({
            icon_tit:merch_tit,
            icon_id:merch_id,
            lists:[]
        })

        this.getallnote();
    },

    // 项目

    bindPickerChangeorder(ret){
        console.log(ret);
        var index=ret.detail.value;
        var merch=this.data.orders;

        var merch_tit=merch[index].title
        var merch_id=merch[index].id

        this.setData({
            order_tit:merch_tit,
            order_id:merch_id,
            lists:[]
        })

        this.getallnote();
    },

        // 人员选择
    bindPickerChangeuser(ret){
            console.log(ret);
            var index=ret.detail.value;
            var merch=this.data.users;
    
            var merch_tit=merch[index].user_nickname
            var merch_id=merch[index].id
    
            this.setData({
                users_tit:merch_tit,
                users_id:merch_id,
                lists:[]
            })
    
            this.getallnote();
    
        },

    // 品牌选择
    bindPickerChange(ret){
        console.log(ret);
        var index=ret.detail.value;
        var merch=this.data.merch;

        var merch_tit=merch[index].title
        var merch_id=merch[index].id

        this.setData({
            merch_tit:merch_tit,
            merch_id:merch_id,
            lists:[]
        })

        this.getallnote();

    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      var infos=wx.getSystemInfoSync();
      console.log(infos);
      console.log(infos.statusBarHeight);

      this.setData({
        tops:infos.statusBarHeight+4
      })    

      this.getallnote();

    },

    addicons(){
        wx.navigateTo({
            url: '/pages/note/add',
        })
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {


        wx.setStorageSync('all', '');


        var that=this;
        api.post({
            url: 'icons/getallicons',
            data: '',
            success: data => {
                that.setData({
                    icons:data.data
                })
            }
        })
        api.post({
            url: 'icons/getalluser',
            data: '',
            success: data => {
                that.setData({
                    users:data.data
                })
            }
        })

        api.post({
            url: 'index/getallmerch',
            data: '',
            success: data => {
                that.setData({
                    merch:data.data.merch
                })
            }
        })

        api.post({
            url: 'icons/getorder',
            data: '',
            success: data => {
                that.setData({
                    orders:data.data
                })
            }
        })

        
        
    },

    goindex(){
      wx.switchTab({
        url: '/pages/index/index',
      })
    },
    project(){
        wx.switchTab({
          url: '/pages/project/index',
        })
    },

    lists(){
        wx.switchTab({
            url: '/pages/list/index',
          })
    },

    me(){

      wx.switchTab({
        url: '/pages/my/my',
      })
    },
    switchTab(){
        wx.switchTab({
            url: '/pages/index/index',
          })
    },
    scanCodeEvent: function(){
      var that = this;
      wx.scanCode({
        onlyFromCamera: true,// 只允许从相机扫码
        success(res){
          JSON.stringify(res)
          console.log(res.result)
          
          wx.navigateTo({
            url: '/pages/about/update?code='+res.result,
          })
   
        },
        fail(ret){
          console.log(ret);
          wx.showToast({
            title: ret.errMsg,
            icon:'none'
          })
        }
      })
    },

    setshow(ret){
        var id=ret.currentTarget.dataset.id;

        this.setData({
            set:1,
            noteid:id
        })
    },

    deletenote(){
        var that=this;
        var id=this.data.noteid;

        this.setData({
            set:0
        })

        wx.showModal({
          title: '提示',
          content: '确定删除吗?',
          complete: (res) => {
        
            if (res.confirm) {
                api.post({
                    url: 'icons/deletenote',
                    data: {id:id},
                    success: data => {

                        wx.showToast({
                          title: data.msg,
                          icon:'none'
                        })
                        that.getallnote();

                        
                    }
                })
            }
          }
        })
    },

    sethide(){
        this.setData({
            set:0
        })
    },

    setopen(ret){
        console.log(ret);
        var that=this;
        var id=ret.currentTarget.dataset.id;

        wx.showModal({
          title: '提示',
          content: '确定已经完成了?',
          complete: (res) => {
        
            if (res.confirm) {
                api.post({
                    url: 'icons/setnoteopen',
                    data: {id:id},
                    success: data => {

                    
                        that.getallnote();

                    }
                })
            }
          }
        })
    },


})